Repository navigation
Conversation
A 32-bit store through a bound or a computed V# emitted two get_bda_write_pointer calls at every store site, one for an aligned dword in the caller and one in write_bda_bytes for the unaligned byte path, each followed by its own note_bda_write. Drivers inline both, so every store carried two copies of the page-table walk and of the written-page probe. write_bda_bytes now also takes the aligned dword: its loop runs once with a 4-byte lookup and a dword store, and otherwise once per byte as before. EmitBdaStore and EmitBdaWrite call it once, and the dword-by-dword fallback of a multi-dword write gets the same single lookup. Each address is looked up, stored, faulted and noted as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0125gxvaRgLMwjs53eqvUzya
Stan2032
pushed a commit
that referenced
this pull request
Dec 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
EmitBdaStore) or a computed one (EmitBdaWrite) emitted two copies of the write path at every store site. The caller emitted an aligned dword path (get_bda_write_pointerandnote_bda_write). For an unaligned address it calledwrite_bda_bytes, whose byte loop has its own lookup and note. Mesa and AMD's LLPC inline both even though the helpers areDontInline(3655, 25774), so every 32-bit store carried two page-table walks and two written-page probes.write_bda_bytesnow also takes the aligned dword. Given 4 bytes at a 4-aligned address, its loop runs once with a 4-byte lookup and a dword store. Otherwise it runs once per byte, as before. Both store paths now call it once.EmitBdaWritestill checks overflow only for 8- and 16-bit writes and for unaligned dwords.BdaContracts: every 8-, 16- and 32-bit write through a bound or a runtime V# now has 1 write lookup and 1 byte-loop call, and the multi-dword fallback has 1 write lookup. Withmain'sSpirvBdaRead.cppit fails witha bound V# write of 32 bits has 2 write lookups and 1 byte-loop calls, not one write lookup in write_bda_bytes.Context: 13538. There, the lookup chain is about 60% of the instructions of the modules RADV cannot compile. This PR removes one write lookup and one note per 32-bit store. It does not touch reads,
DefineBdaLookupornote_bda_write. On the title itself the change does little: dantdmdarealguy compiled the real 0x1ac4 and 0x1b14 programs with it on an RTX 5080 (driver 621.14), and the difference was about 5%, inside the 5-8% run-to-run noise, with about 2% less peak memory. Those modules have only 6 BDA store sites; their size is in the reads (2,101read_bda_span_stopand 4,166record_bda_faultcalls) and the run-time image mode switches. So the numbers below apply to store-heavy programs, not to that one. 22944 removes thenote_bda_writecalls next to the stores this PR moves, so whichever of the two lands second drops or keeps that one call; the single lookup per store stays either way.Size. I measured a synthetic table-call program: the waterfall
s_swappc_b64of theSplitTableCallRuntests, linked to N callees. Each callee does 8global_load_dwordand 4 or 8global_store_dwordthrough a pointer from user data.DontInlinewas cleared, which approximates what the driver compiles.spirv-opt -OwithStorePages(spec constant 8239) frozen to 0 or 1, and its instructions were counted.mainThat is about 390 fewer instructions per 32-bit store with StorePages=0 and about 540 with StorePages=1. A store cost about 930 and 1,430 instructions before. Emitted SPIR-V shrinks by about 75 words per store.
For a driver that keeps the calls, each 32-bit store site in
mainnow makes 1 call instead of 3. In the 4-callee, 8-store program that is 192 calls frommaindown to 128. 6706 found that NVIDIA's pipeline creation time tracks the number of calls.Compile time on lavapipe. These are the same programs with
MESA_SHADER_CACHE_DISABLE=true. lavapipe compiles LLVM at the first dispatch. The runs alternatemain, PR, PR,mainwith the same test binary; onlylibSceAgcDriver.prxdiffers.main: first dispatch, peak RSSPipeline creation itself (NIR) took 4.5 and 4.0 s on
mainagainst 3.1 and 1.7 s with this PR (8 stores per callee), and 2.7 and 1.8 s against 1.3 and 1.1 s (4 stores). Every run wrote all 32 lanes.Pipeline creation on RADV. I compiled the same SPIR-V modules with RADV (Mesa 25.2.8, ACO) through Mesa's
amdgpu_noop_drm_shim, which lets RADV build pipelines without the GPU. A small standalone program builds one compute pipeline with the module's layout: storage buffers at bindings 0 (3 of them), 59, 60 and 61, 128 bytes of push constants, and a required subgroup size of 32. It timesvkCreateComputePipelinesand reads the process's peak RSS, withMESA_SHADER_CACHE_DISABLE=true. The validation layer reports nothing for this setup. Peak RSS is the same on every run. Time varies by up to about 25% between runs on this shared machine, so the 12- and 16-callee rows on RDNA2 list three runs each.AMDGPU_GPU_ID=navi21),maingfx1201),mainOn RADV, pipeline creation takes about half as long, and peak memory drops by 30-40%. Memory grows faster than linearly with the number of callees on both sides, as in 13538.
Together with 22944. 22944 (head ac8141c, merged with
main76d0a4a) removesnote_bda_write. I also applied this PR on top of it, keeping the single write lookup per store and dropping its one note call. The table shows RADV through the shim on RDNA2. Each pairing gives the same output and memory hashes, andagc_driver_bda_devicepasses on the combination. Both PRs rewrite the 32-bit store path inSpirvBdaRead.cpp(EmitBdaStoreAtand the store body), so they conflict textually; the numbers below come from a hand merge, and whichever merges second needs a rebase.mainThe two changes add up: on top of 22944, this PR still cuts the driver-inlined size by 20% (224,628 to 179,598 instructions for 16 callees with 8 stores each).
For 1, 2 and 4 callees with 4 or 8 stores each, I hashed the program's output and the guest block it stores into after the dispatch, with address randomization off so the block's buffer descriptor matches. All 6 programs hash the same on
mainand on this PR.Pipeline creation on NVIDIA. These are the same modules on a GeForce GTX 1050, Windows 11, driver 582.67, Vulkan 1.4.312. The program is the same standalone pipeline tool, built for Windows; it adds a random
OpSourceExtensionto each module so the driver's shader cache cannot serve it. Each cell is the median of 4 runs over two rounds in alternating order, givingvkCreateComputePipelinestime and peak process memory.mainOn NVIDIA,
main's time grows 2.7x and then 3.7x for each doubling of callees, and this PR's 1.8x and then 2.3x, so the gap widens with size. On this driver, 22944 adds nothing on top of this PR.The tools and scripts behind these numbers, with the drm-shim setup, are on bench/compute-shader-cost in my fork.
Tested
Ubuntu 24.04.5, kernel 6.18, lavapipe (llvmpipe, Mesa 25.2.8, LLVM 20.1.2), and RADV (Mesa 25.2.8) compiling only, through the drm-shim. No hardware GPU on this machine.
agc_driver_bda_devicewithANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1and the Khronos validation layer 1.4.363.1 passes, with noVUID-line.mainand on this PR. They run unmodified on NVIDIA; see below.bda|store|_write|flat|global|runtime_format|runtime_buffer|shader_memory|atomic|buffer_load|unaligned|straddle|masked(host-only suites excluded) with the validation layer. Both runs used the same test binaries; onlylibSceAgcDriver.prxdiffered.main: 297 pass.agc_driver_flat_aperture_lds_bounds(28316 fixes it),agc_driver_write_back_guest_newer, andagc_driver_image_store_volume_through_plane(not built).mainalso failsagc_driver_bda_device, on the new contract check.VUID-line in either run.python3 tools/check_conventions.py --base upstream/mainandgit diff --checkpass.On NVIDIA hardware, Dec 1: NVIDIA GeForce GTX 1050 (the machine's only Vulkan device), driver 582.67, Vulkan 1.4.312, validation layer 1.4.363, Windows 11, built with WinLibs GCC 15.2.0. This branch is 30 commits behind
main, so I applied its commit ontomain483b81f and compared that withmain483b81f on the same machine; the branch head itself was not built.bda|store|_write, withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer: 270 pass, 0 fail and 3 skip on bothmainand this change. The skipped tests areagc_driver_host_write_shadowed_unit,agc_driver_idle_store_over_unmapandagc_driver_mesh_vector_window_writes, on both.agc_driver_bda_device, which holds the new contract check, passes with this change. On this GPU it also runs the BDA read and multi-dword write execution cases that it skips on a CPU device; they pass on bothmainand this change.VUID-line.Not tested: AMD hardware, AMD's own driver (LLPC), and any title. The RADV numbers come from the shim and the NVIDIA timings from pipeline creation only, so both cover compilation; only the NVIDIA ctest run above executed on a GPU. Numbers from a real store-heavy compute program would be the useful next measurement.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)mainhttps://claude.ai/code/session_0125gxvaRgLMwjs53eqvUzya
Generated by Claude Code